home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 281_01 / tdata.c < prev    next >
C/C++ Source or Header  |  1988-10-05  |  18KB  |  637 lines

  1. /*  tdata.c
  2.  *
  3.  *  Test program for data entry functions
  4.  *
  5.  */
  6.  
  7.  
  8. /*
  9.  *  This program demonstrates some of the data entry functions contained
  10.  *  in the Unicorn Library.  While the author intends to add many more
  11.  *  functions and a much broader capability to the library this early
  12.  *  version is being released.    Planned for a future release is a form
  13.  *  design utility that will allow easy field definitions.  This utility
  14.  *  should be able to take an ASCII description file and write the C
  15.  *  code for the fields.  This should save considerable time in form
  16.  *  development.  At present this is in the early planning stages so
  17.  *  no final release date has been set.
  18.  *
  19.  */
  20.  
  21.  
  22.  
  23. #include <stdio.h>
  24.  
  25. #include "uc_defs.h"
  26. #include "uc_glob.h"
  27.  
  28. #include "wn_defs.h"
  29. #include "wn_glob.h"
  30.  
  31. WINDOWPTR  fmp;
  32. WINDOWPTR  wn1;
  33. WINDOWPTR  wn_main;
  34. WINDOWPTR  wn_title;
  35. WINDOWPTR  wn_make();
  36. char       *strblnk();
  37. FIELDPTR   fld_make();
  38. char       *str_save();
  39. FIELDPTR   fld[ 8 ];
  40.  
  41.  
  42. void main( void )
  43. {
  44.    int      i;
  45.  
  46.    char   *rec;
  47.    char   *rec_mask;
  48.  
  49.    char   *fname;
  50.    char   *f_mask;
  51.  
  52.    char   *lname;
  53.    char   *l_mask;
  54.  
  55.    char   *addr;
  56.    char   *ad_mask;
  57.  
  58.    char   *city;
  59.    char   *c_mask;
  60.  
  61.    char   *state;
  62.    char   *s_mask;
  63.  
  64.    char   *zip;
  65.    char   *z_mask;
  66.  
  67.    char   *phone;
  68.    char   *p_mask;
  69.  
  70.    char   *birthday;
  71.    char   *b_mask;
  72.  
  73.    char   *amount;
  74.    char   *a_mask;
  75.  
  76.    int      before6();
  77.    int      after6();
  78.    int      on_key();
  79.    int      val_state();
  80.    int      val_date();
  81.  
  82.  
  83.    char   *xx;
  84.  
  85.                 /*    Save the users original cursor status */
  86.    cur_save();
  87.  
  88.  
  89.                 /*    This function inititalizes the system */
  90.    uc_init();
  91.    if ( mouse_exist )
  92.       m_flagdec();
  93.                 /*    This window is built as a full screen */
  94.                 /*    window to save the users original     */
  95.                 /*    screen.  Bringing this window down at */
  96.                 /*    the end of the demo the screen will be*/
  97.                 /*    restored to its original state.       */
  98.  
  99.    wn_main = wn_make( 0, 0, 24, 80 );
  100.    wn_wnclr( wn_main, mk_att( BLACK, CYAN + BRIGHT ) );
  101.    wn_bclr( wn_main, mk_att( BLACK, BROWN + BRIGHT ) );
  102.    wn_clear( wn_main );
  103.    wn_margin( wn_main, 5 );
  104.    wn_mkbdr( wn_main, BDR_SLNP );
  105.  
  106.    wn_dsply( wn_main );
  107.  
  108.  
  109.  
  110.            /* Make a window for display of the Unicorn Software   */
  111.            /* address and phone number.  The phone is the authors */
  112.            /* home phone.  Call after 6pm Pacific time on          */
  113.            /* weeknights please.  The author must moonlight for   */
  114.            /* about 40 hours a week as a software engineer in     */
  115.            /* order to support this shareware hobby.          */
  116.  
  117.    wn_title = wn_make( 0, 0, 7, 80 );
  118.    wn_wnclr( wn_title, mk_att( BLACK, BROWN + BRIGHT ) );
  119.    wn_bclr( wn_title, mk_att( BLACK, BROWN + BRIGHT ) );
  120.    wn_clear( wn_title );
  121.  
  122.    wn_mkbdr( wn_title, BDR_SLNP );
  123.  
  124.    wn_dsply( wn_title );
  125.  
  126.    wn_printf( wn_title, "\t\t\t\t\t         Unicorn Software\n" );
  127.    wn_printf( wn_title, "\t\t\t\t\tP.O Box 3214 Kirkland, WA 98083-3214\n" );
  128.    wn_printf( wn_title, "\t\t\t\t\t         ( 206 ) 823-4656\n" );
  129.    wn_wnclr( wn_title, mk_att( BLACK, MAGENTA + BRIGHT ) );
  130.    wn_printf( wn_title, "\t\t\t\t\t      No collect calls Please" );
  131.  
  132.  
  133.                /*  This was inititalized in the uc_init   */
  134.                /*  call but then a window ( wn_main ) was */
  135.                /*  placed on top of it so now we must move*/
  136.                /* it to the front.                  */
  137.    wn_front( wnd_message );
  138.  
  139.  
  140.  
  141.                 /* Now we will define the data form and   */
  142.                 /* start attaching fields to the window   */
  143.  
  144.    fmp = wn_make( 5, 0, 14, 80 );
  145.    wn_wnclr( fmp, mk_att( BLUE, CYAN + BRIGHT ) );
  146.    wn_bclr( fmp, mk_att( BLUE, BROWN + BRIGHT ) );
  147.    wn_clear( fmp );
  148.  
  149.    wn_mkbdr( fmp, BDR_DLNP );
  150.  
  151.    wn_printf( fmp,
  152.     "                Unicorn Software Data Entry System 1.00" );
  153.    wn_printf( fmp, "\n\n\n\n\n\n\n\n\n\n\n" );
  154.    wn_printf( fmp,
  155.     "                Press F1 for help  -  ESC to leave form" );
  156.  
  157.                   /* display the form on the screen       */
  158.    wn_dsply( fmp );
  159.  
  160.                   /* prepare to add data fields to window */
  161.    fld_init( fmp );
  162.  
  163.  
  164.  
  165.                   /* This is the first field          */
  166.    rec        = strblnk( 8 );
  167.    rec_mask = strblnk( 8 );
  168.  
  169.    strcpy( rec,       "    " );
  170.    strcpy( rec_mask,  "9999" );
  171.  
  172.    fld[ 0 ] = fld_make( fmp, 2, 5, "Record Number ", 19,
  173.                      rec_mask, rec, FLD_ZERO_FILL );
  174.    if ( fld[ 0 ] == ( FIELDPTR ) NULL )
  175.    {
  176.       fld_err( str_save( "Out of memory for field 0" ) );
  177.       exit( 1 );
  178.    }
  179.    xx = str_save( "Enter the current record number for this person" );
  180.    sf_message( fld[ 0 ], xx );
  181.    xx = str_save( "The record number must be an integer" );
  182.    sf_hlptag( fld[ 0 ], xx );
  183.                 /* The helptag parameter is currently */
  184.                 /* nothing more than a message.  In a */
  185.                 /* later release it will become a true*/
  186.                 /* help tag that may be used to find  */
  187.                 /* the help message in an ASCII text  */
  188.                 /* file.  The user will then be able  */
  189.                 /* to scroll this file in the help    */
  190.                 /* window.  This will allow the       */
  191.                 /* creation of a full capability help */
  192.                 /* system that is context sensitive.  */
  193.  
  194.  
  195.    fname    = strblnk( 18 );
  196.    f_mask   = strblnk( 18 );
  197.  
  198.    strcpy( fname,   "               " );
  199.    strcpy( f_mask,  "!AAAAAAAAAAAAAA" );
  200.  
  201.    fld[ 1 ] = fld_make( fmp, 3, 5, "First Name    ", 19,
  202.                     f_mask, fname, FLD_ALPHA_NUMERIC );
  203.    if ( fld[ 1 ] == ( FIELDPTR ) NULL )
  204.    {
  205.       fld_err( str_save( "Out of memory for field 1" ) );
  206.       exit( 1 );
  207.    }
  208.    xx = str_save( "Enter the first name only ( no middle initial )" );
  209.    sf_message( fld[ 1 ], xx );
  210.    xx = str_save( "Enter the full legal first name" );
  211.    sf_hlptag( fld[ 1 ], xx );
  212.  
  213.  
  214.  
  215.  
  216.  
  217.    lname    = strblnk( 18 );
  218.    l_mask   = strblnk( 18 );
  219.  
  220.    strcpy( lname,   "Miller         " );
  221.    strcpy( l_mask,  "!AAAAAAAAAAAAAA" );
  222.  
  223.    fld[ 2 ] = fld_make( fmp, 4, 5, "Last Name     ", 19,
  224.                      l_mask, lname, FLD_ALPHA_NUMERIC );
  225.    if ( fld[ 2 ] == ( FIELDPTR ) NULL )
  226.    {
  227.       fld_err( str_save( "Out of memory for field 2" ) );
  228.       exit( 1 );
  229.    }
  230.    xx = str_save( "Enter the last name for this person" );
  231.    sf_message( fld[ 2 ], xx );
  232.    xx = str_save( "Enter the full legal last name" );
  233.    sf_hlptag( fld[ 2 ], xx );
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.    addr     = strblnk( 28 );
  241.    ad_mask  = strblnk( 28 );
  242.  
  243.    strcpy( addr,     "                     " );
  244.    strcpy( ad_mask,  "XXXXXXXXXXXXXXXXXXXXX" );
  245.  
  246.    fld[ 3 ] = fld_make( fmp, 5, 5, "Address       ", 19,
  247.                      ad_mask, addr, FLD_ALPHA_NUMERIC );
  248.    if ( fld[ 3 ] == ( FIELDPTR ) NULL )
  249.    {
  250.       fld_err( str_save( "Out of memory for field 3" ) );
  251.       exit( 1 );
  252.    }
  253.    xx = str_save( "Enter the full street address" );
  254.    sf_message( fld[ 3 ], xx );
  255.    xx = str_save( "Include apartment number if needed" );
  256.    sf_hlptag( fld[ 3 ], xx );
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.    city     = strblnk( 18 );
  265.    c_mask   = strblnk( 18 );
  266.  
  267.    strcpy( city,     "                " );
  268.    strcpy( c_mask,   "!AAAAAAAAAAAAAAA" );
  269.  
  270.    fld[ 4 ] = fld_make( fmp, 6, 5, "City          ", 19,
  271.                      c_mask, city, FLD_ALPHA_NUMERIC );
  272.    if ( fld[ 4 ] == ( FIELDPTR ) NULL )
  273.    {
  274.       fld_err( str_save( "Out of memory for field 4" ) );
  275.       exit( 1 );
  276.    }
  277.    xx = str_save( "Enter this person's city of residence" );
  278.    sf_message( fld[ 4 ], xx );
  279.    xx = str_save( "This must be the city of legal residence" );
  280.    sf_hlptag( fld[ 4 ], xx );
  281.  
  282.  
  283.  
  284.  
  285.    state    = strblnk( 4 );
  286.    s_mask   = strblnk( 4 );
  287.  
  288.    strcpy( state,    "  " );
  289.    strcpy( s_mask,   "!!" );
  290.  
  291.    fld[ 5 ] = fld_make( fmp, 6, 42, "State ", 50,
  292.                      s_mask, state, FLD_ALPHA_NUMERIC );
  293.    if ( fld[ 5 ] == ( FIELDPTR ) NULL )
  294.    {
  295.       fld_err( str_save( "Out of memory for field 5" ) );
  296.       exit( 1 );
  297.    }
  298.    xx = str_save( "Enter the state of residence" );
  299.    sf_message( fld[ 5 ], xx );
  300.    xx = str_save( "Use proper postal abbreviations only" );
  301.    sf_hlptag( fld[ 5 ], xx );
  302.    sf_val( fld[ 5 ], val_state );
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.    zip        = strblnk( 8 );
  310.    z_mas